# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Mubashshir <ahmubashshir@gmail.com>

_name=jq.py
pkgname=python-jq
pkgver=1.4.1
pkgrel=2
pkgdesc='Python bindings for jq'
arch=('loong64' 'x86_64')
url=https://github.com/mwilliamson/jq.py
license=('BSD')
depends=('jq' 'python')
makedepends=('cython' 'git' 'python-build' 'python-installer'
             'python-setuptools' 'python-wheel')
checkdepends=('python-pytest')
source=("git+$url.git#tag=$pkgver"
        'jq-py-setup.patch')
b2sums=('SKIP'
        'ea5061ea7d4bad240c0df82dec3a430a583f1596685a8b4b36f1a0ee6bcae745586f5b1abf3985a8bb0e13523ef084bd6e05f9f430df247c2a6ec2044f99017a')

# Devendor
prepare() {
  cd $_name
  patch --forward --input=../jq-py-setup.patch
}

build() {
  cd $_name
  cython -3 jq.pyx
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd $_name
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest
}

package() {
  cd $_name
  python -m installer --destdir="$pkgdir" dist/*.whl

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/jq-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
